package com.example.administrator.szb.activity;

import android.content.Intent;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;
import com.example.administrator.szb.R;
import com.example.administrator.szb.adapter.BaseAdapter;
import com.example.administrator.szb.activity.base.BaseActivity;
import com.example.administrator.szb.bean.BusinessBean;
import com.example.administrator.szb.bean.ColorBean;
import com.example.administrator.szb.bean.GWJGBean;
import com.example.administrator.szb.bean.IndexBean;
import com.example.administrator.szb.bean.StarBean;
import com.example.administrator.szb.tinkerutil.SampleApplicationLike;
import com.example.administrator.szb.fragments.fragment_forTab.home.adapter.JGadapter;
import com.example.administrator.szb.http.HttpUtil;
import com.example.administrator.szb.http.URLAddress;
import com.example.administrator.szb.util.Toasts;
import com.example.administrator.szb.view.MyLinearLayout;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by D N on 2017/10/13.
 */

public class SearchYWActivity extends BaseActivity {

    @Bind(R.id.toolbar_fh_search_yw)
    ImageView toolbarFhSearchYw;
    @Bind(R.id.toolbar_title_search_yw)
    TextView toolbarTitleSearchYw;
    @Bind(R.id.image_search_yw)
    ImageView imageSearchYw;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.search_yw_one)
    MyLinearLayout searchYwOne;
    @Bind(R.id.search_yw_two)
    MyLinearLayout searchYwTwo;
    @Bind(R.id.search_yw_three)
    MyLinearLayout searchYwThree;
    @Bind(R.id.search_yw_four)
    MyLinearLayout searchYwFour;
    @Bind(R.id.search_yw_recyclerview)
    ListView searchYwRecyclerview;
    @Bind(R.id.search_yw_zero)
    LinearLayout searchYwZero;

    List<GWJGBean.DataBean.ConditListBean> mdata;
    List<BusinessBean.DataBean> mdata_four_two = new ArrayList<>();
    HashMap<Integer,BusinessBean> yw_map = new HashMap<>();//缓存数据
    boolean flag = true;//控制第一次显示旁边的线条
    BaseAdapter<GWJGBean.DataBean.ConditListBean.NextBean> adapter;
    BaseAdapter<GWJGBean.DataBean.ConditListBean> adapter_four;
    PopupWindow popupWindow;
    String title;
    int id;
    //BusinessBean businessBean_two;

    @Bind(R.id.search_yw_checkbox_one)
    CheckBox searchYwCheckboxOne;
    @Bind(R.id.search_yw_checkbox_two)
    CheckBox searchYwCheckboxTwo;
    @Bind(R.id.search_yw_checkbox_three)
    CheckBox searchYwCheckboxThree;
    @Bind(R.id.search_yw_checkbox_four)
    CheckBox searchYwCheckboxFour;

    BaseAdapter<BusinessBean.DataBean> adapter_four_two;
    RecyclerView recyclerView_two;
    BaseAdapter<IndexBean.DataBean.HotCounBean> gwjg_adapter;


    int current_page = 1;
    int per_page = 10;

    GWJGBean gwjgBean;

    HashMap<Integer,String> search_id = new HashMap<Integer, String>(){
        @Override
        public String toString() {
            String id = "";
            Set<Integer> keySet = search_id.keySet();
            //有了Set集合就可以获取其迭代器，取值
            Iterator<Integer> it = keySet.iterator();

            while (it.hasNext()){
                Integer i = it.next();
                id = search_id.get(i) + "," + id;
            }
            return id;
        }
    };//搜索条件id
    private int cj_map_id;
    private int ci_position = 3;

    interface CallBackYW{
        void doSomething(int id);
    }
    CallBackYW callback;//筛选recyclerview
    View error_head;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search_yw_activity);
        ButterKnife.bind(this);



        //initView();
        requestGWData(0+"");
    }
    JGadapter adapters;
    private void initRecyclerview() {
        searchYwRecyclerview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(SearchYWActivity.this, JGXQActivity.class);
                intent.putExtra("id", mdata.get(position).getId());
                intent.putExtra("id_type", id);
                startActivity(intent);
            }
        });

        if (mdata.size() == 0) {

            String info = "未搜索到相关机构";
            Toasts.show(this,""+info);
        }
        if (adapters==null){
            adapters = new JGadapter(this,mdata);
            searchYwRecyclerview.setAdapter(adapters);
        }else {
            adapters.notifyDataSetChanged();
        }

    }

    private void initItem(BaseAdapter.BaseViewHolder holder, GWJGBean.DataBean.DataListBean dataBean, int position) {
        if (!TextUtils.isEmpty(dataBean.getZhenshi_img())) {
            Glide.with(this).load(dataBean.getZhenshi_img()).into((ImageView) (holder).getView(R.id.imageView20));
        }
        if (!TextUtils.isEmpty(dataBean.getName())){
            ((TextView) holder.getView(R.id.textView49)).setText(dataBean.getCompany() + "-" + dataBean.getName());
        }else{
            ((TextView) holder.getView(R.id.textView49)).setText(dataBean.getCompany());
        }
        if (dataBean.getCompany() == null){
            ((TextView)holder.getView(R.id.textView50)).setVisibility(View.INVISIBLE);
        }else{
            ((TextView)holder.getView(R.id.textView50)).setVisibility(View.INVISIBLE);
            //((TextView)holder.getView(R.id.textView50)).setText(dataBean.getCompany());
        }
        if (dataBean.getCity() == null){
            ((TextView)holder.getView(R.id.textView51)).setVisibility(View.INVISIBLE);
        }else {
            ((TextView)holder.getView(R.id.textView51)).setText((String)dataBean.getCity());
        }


        /**
         * 显示业务标签
         */

        showYW(dataBean,holder,position);

        /**
         * 显示星星
         */
        showStar(dataBean,holder);
    }
    private void showStar(final GWJGBean.DataBean.DataListBean dataBean, BaseAdapter.BaseViewHolder holder) {
        final ArrayList<StarBean> mdata = new ArrayList<>();
        RecyclerView recyclerView = ((RecyclerView)holder.getView(R.id.zdyh_recyclerview_star));
        recyclerView.setLayoutManager(new GridLayoutManager(this,5));
        for (int i = 0; i < 5; i++) {
            StarBean b = new StarBean();
            mdata.add(b);
        }
        BaseAdapter<StarBean> adapter = new BaseAdapter<StarBean>(SearchYWActivity.this, mdata) {
            @Override
            public void convert(int position, BaseViewHolder holder, StarBean starBean) {
                ((ImageView) holder.getView(R.id.view_zdyh_star)).setImageResource(R.drawable.star_hui);
                if (dataBean.getEvaluate() / 2 > position){
                    ((ImageView) holder.getView(R.id.view_zdyh_star)).setImageResource(R.drawable.start);
                }
                if (position == dataBean.getEvaluate() / 2 + dataBean.getEvaluate() % 2 - 1 && dataBean.getEvaluate() % 2 != 0) {
                    ((ImageView) holder.getView(R.id.view_zdyh_star)).setImageResource(R.drawable.star_half);
                }
            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.view_zdyh_star;
            }
        };
        recyclerView.setAdapter(adapter);
    }

    private void showYW(GWJGBean.DataBean.DataListBean dataBean, BaseAdapter.BaseViewHolder holder, final int position) {

        RecyclerView recyclerView = ((RecyclerView)holder.getView(R.id.zdyh_recyclerview_ywbq));
        recyclerView.setLayoutManager(new GridLayoutManager(this,4));
        /**
         * 截获事件，业务标签的recyclerview 会劫持事件，如果不加上点击失效
         */
        recyclerView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {//此处是点击按下时才执行跳转动作
                    // Toasts.show(mActivity, "....", Toast.LENGTH_SHORT);
                    Intent intent = new Intent(SearchYWActivity.this,JGXQActivity.class);
                    intent.putExtra("id",gwjgBean.getData().getDataList().get(position).getId());
                    intent.putExtra("id_type",id);
                    startActivity(intent);

                    //startActivity(new Intent(ProfileEdit.this, EditDepartment.class));
                }
                return false;
            }
        });

        BaseAdapter<GWJGBean.DataBean.DataListBean.BusinessIdBean> adapter = new BaseAdapter<GWJGBean.DataBean.DataListBean.BusinessIdBean>(this,dataBean.getBusiness_id(),4) {
            @Override
            public void convert(int position, BaseViewHolder holder, GWJGBean.DataBean.DataListBean.BusinessIdBean businessBean) {
                GradientDrawable drawable;
                ((TextView) holder.getView(R.id.view_jgxq_text)).setText(businessBean.getTitle());
                try {
                    Class<?> c = null;
                    c = Class.forName("bean.ColorBean$DataBean");
                    ColorBean.DataBean obj = (ColorBean.DataBean) c.newInstance();
                    //第一个参数写的是方法名,第二个\第三个\...写的是方法参数列表中参数的类型
                    Method method=c.getMethod("get_$"+businessBean.getId());
                   // String str2= (String) method.invoke(WecomeActivity.colorBean.getData());


                    drawable = (GradientDrawable)  ((TextView) holder.getView(R.id.view_jgxq_text)).getBackground();
                   // drawable.setColor(Color.parseColor(str2));
                }catch (Exception e){

                }


            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.view_jgxq_item;
            }
        };
        recyclerView.setAdapter(adapter);
    }

    private void requestGWData(String arr) {
        id = getIntent().getIntExtra("id",0);
        HashMap<String,String> map = new HashMap<>();
        map.put("code", HttpUtil.getParam());
        map.put("id",id+"");
        map.put("arr",""+arr);
        map.put("current_page",current_page+"");
        map.put("per_page",per_page+"");
        HttpUtil.RequestGsonPost(SampleApplicationLike.getQueueInstance(), Request.Method.POST, GWJGBean.class, URLAddress.URLBASE + URLAddress.URL_GWJG, map, new Response.Listener() {
            @Override
            public void onResponse(Object response) {
                gwjgBean = (GWJGBean) response;
                if (gwjgBean.getResult() == 1) {
                    initRecyclerview();
                    initView();
                    if(gwjg_adapter != null){
                        gwjg_adapter.mDatas = gwjgBean.getData().getDataList();
                        gwjg_adapter.notifyDataSetChanged();
                    }
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.toString();
            }
        });
    }

    private void initView() {
        toolbarTitleSearchYw.setText(getIntent().getStringExtra("title"));
        id = getIntent().getIntExtra("id", -1);
        requestData();

    }

    private void requestData() {

        mdata = gwjgBean.getData().getConditList();

        initChooseBar();


    }

    /**
     * 初始化次级title
     */
    private void initChooseBar() {

        String one = TextUtils.isEmpty(gwjgBean.getData().getConditList().get(0).getShowtitle())?gwjgBean.getData().getConditList().get(0).getTitle():gwjgBean.getData().getConditList().get(0).getShowtitle();
        String two = TextUtils.isEmpty(gwjgBean.getData().getConditList().get(1).getShowtitle())?gwjgBean.getData().getConditList().get(1).getTitle():gwjgBean.getData().getConditList().get(1).getShowtitle();
        String three = TextUtils.isEmpty(gwjgBean.getData().getConditList().get(2).getShowtitle())?gwjgBean.getData().getConditList().get(2).getTitle():gwjgBean.getData().getConditList().get(2).getShowtitle();

        String four ="";
       try{
         four = TextUtils.isEmpty(gwjgBean.getData().getConditList().get(3).getShowtitle())?gwjgBean.getData().getConditList().get(3).getTitle():gwjgBean.getData().getConditList().get(3).getShowtitle();

       }catch (Exception e){

       }

        for (int i = 0; i < gwjgBean.getData().getConditList().size(); i++) {
            search_id.put(gwjgBean.getData().getConditList().get(i).getId(),0+"");
        }

        searchYwCheckboxOne.setSelected(true);
        searchYwCheckboxTwo.setSelected(true);
        searchYwCheckboxThree.setSelected(true);
        searchYwCheckboxFour.setSelected(true);
        if (mdata.size()>4) {
            searchYwCheckboxOne.setText(one);
            searchYwCheckboxTwo.setText(two);
            searchYwCheckboxThree.setText(three);
            searchYwCheckboxFour.setText("筛选");
        }else{
            switch (mdata.size()){
                case 0:
                    break;
                case 1:
                    searchYwCheckboxOne.setText(one);
                    searchYwTwo.setVisibility(View.GONE);
                    searchYwThree.setVisibility(View.GONE);
                    searchYwFour.setVisibility(View.GONE);
                    break;
                case 2:
                    searchYwCheckboxOne.setText(one);
                    searchYwCheckboxTwo.setText(two);
                    searchYwThree.setVisibility(View.GONE);
                    searchYwFour.setVisibility(View.GONE);
                    break;
                case 3:
                    searchYwCheckboxOne.setText(one);
                    searchYwCheckboxTwo.setText(two);
                    searchYwCheckboxThree.setText(three);
                    searchYwFour.setVisibility(View.GONE);
                    break;
                case 4:
                    searchYwCheckboxOne.setText(one);
                    searchYwCheckboxTwo.setText(two);
                    searchYwCheckboxThree.setText(three);
                    searchYwCheckboxFour.setText(four);
                    break;
            }
        }




    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    @OnClick({R.id.toolbar_fh_search_yw, R.id.image_search_yw, R.id.search_yw_one, R.id.search_yw_two, R.id.search_yw_three, R.id.search_yw_four})
    public void onViewClicked(final View view) {
        switch (view.getId()) {
            case R.id.toolbar_fh_search_yw:
                finish();
                break;
            case R.id.image_search_yw:
                startActivity(new Intent(this, SearchActivity.class));
                break;
            case R.id.search_yw_one:
                searchYwOne.setStatu(true);
                initCjView(0);
                //requestDataCj(mdata.get(0).getId());
                break;
            case R.id.search_yw_two:
                searchYwTwo.setStatu(true);
                initCjView(1);
                //requestDataCj(businessBean_two.getData().get(1).getId());
                break;
            case R.id.search_yw_three:
                searchYwThree.setStatu(true);
                initCjView(2);
                //requestDataCj(businessBean_two.getData().get(2).getId());
                break;
            case R.id.search_yw_four:
                searchYwFour.setStatu(true);
                if (mdata.size()>4){

                   // handlerFour(mdata.get(ci_position).getId());//处理业务标签大于4的情况
                    adapter_four = new BaseAdapter<GWJGBean.DataBean.ConditListBean>(this, gwjgBean.getData().getConditList()) {
                        @Override
                        public void convert(int position, BaseViewHolder holder, GWJGBean.DataBean.ConditListBean bean) {
                            try{

                                if (bean.getLineshow() == 0){
                                    holder.getView(R.id.search_yw_sx_show_one).setVisibility(View.VISIBLE);
                                }else{
                                    holder.getView(R.id.search_yw_sx_show_one).setVisibility(View.INVISIBLE);
                                }

                                if (position ==3 && flag) {
                                    flag = false;
                                    holder.getView(R.id.search_yw_sx_show_one).setVisibility(View.INVISIBLE);
                                }


                               if (TextUtils.isEmpty(bean.getShowtitle())){
                                   ((TextView)holder.getView(R.id.search_yw_sx_text_one)).setText(bean.getTitle());
                               }else{
                                   ((TextView)holder.getView(R.id.search_yw_sx_text_one)).setText(bean.getShowtitle());
                               }


                            }catch (Exception e){

                            }
                        }

                        @Override
                        public int getLayoutId(int viewType) {
                            if (viewType<3){
                                return R.layout.view_empty_item;
                            }
                            return R.layout.view_popuwindow_search_yw_sx_item_one;
                        }
                    };


                    adapter_four_two = new BaseAdapter<BusinessBean.DataBean>(SearchYWActivity.this,mdata_four_two) {
                        @Override
                        public void convert(int position, BaseViewHolder holder, BusinessBean.DataBean dataBean) {
                            ((TextView)holder.getView(R.id.view_search_yw_sx_item_two)).setText(dataBean.getTitle());
                            if (dataBean.getIsChoose() == 1) {
                                ((TextView) holder.getView(R.id.view_search_yw_sx_item_two)).setTextColor(getResources().getColor(R.color.tab_choose));
                            } else {
                                ((TextView) holder.getView(R.id.view_search_yw_sx_item_two)).setTextColor(getResources().getColor(R.color.toolbar_home));
                            }
                        }

                        @Override
                        public int getLayoutId(int viewType) {
                            return R.layout.view_popuwindow_search_yw_sx_item_two;
                        }
                    };
                    showPopupwindowSX(R.layout.view_popuwindow_search_yw_sx, searchYwFour, adapter_four, adapter_four_two);

                }else {
                    initCjView(3);
                }
                break;
        }
    }


//    private void handlerFour(final int id) {
//
//        if (yw_map.get(id) != null){
//            cj_map_id = id;
//            mdata_four_two = yw_map.get(id).getData();
//            callback.doSomething(id);
//        }else {
//            HashMap<String, String> map = new HashMap<>();
//            map.put("code", HttpUtil.getParam());
//            map.put("business_id", "" + id);
//            HttpUtil.RequestGsonPost(SampleApplicationLike.getQueueInstance(), Request.Method.POST, BusinessBean.class, URLAddress.URLBASE + URLAddress.URL_Business, map, new Response.Listener() {
//                @RequiresApi(api = Build.VERSION_CODES.KITKAT)
//                @Override
//                public void onResponse(Object response) {
//
//                    BusinessBean businessBean = (BusinessBean) response;
//                    BusinessBean.DataBean dataBean = new BusinessBean.DataBean();
//                    dataBean.setTitle("不限");
//                    dataBean.setId(0);
//                    businessBean.getData().add(0,dataBean);
//
//                    yw_map.put(id, businessBean);
//                    cj_map_id = id;
//                    callback.doSomething(id);
//                }
//            }, new Response.ErrorListener() {
//                @Override
//                public void onErrorResponse(VolleyError error) {
//
//                }
//            });
//        }
//
//
//
//    }



    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    private void initCjView(final int id) {
        adapter = new BaseAdapter<GWJGBean.DataBean.ConditListBean.NextBean>(this,gwjgBean.getData().getConditList().get(id).getNext()) {
            @Override
            public void convert(int position, BaseViewHolder holder, GWJGBean.DataBean.ConditListBean.NextBean bean) {
                ((TextView) holder.getView(R.id.base_tjzl_popuwindow_text_item)).setText(bean.getTitle());
                if (bean.getIsChoose() == 1) {
                    ((TextView) holder.getView(R.id.base_tjzl_popuwindow_text_item)).setTextColor(getResources().getColor(R.color.tab_choose));
                } else {
                    ((TextView) holder.getView(R.id.base_tjzl_popuwindow_text_item)).setTextColor(getResources().getColor(R.color.toolbar_home));
                }
            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.view_popuwindow_base_tjzl_item;
            }
        };
        showPopupwindowSX(R.layout.view_popuwindow_base_tjzl, searchYwZero, adapter, null);
        adapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                popupWindow.dismiss();
                hideAllStatu();

                for (int i = 0; i < yw_map.get(id).getData().size(); i++) {
                    yw_map.get(id).getData().get(i).setIsChoose(0);
                    yw_map.get(id).getData().get(i).setHeadIsChoose(0);
                }
                yw_map.get(id).getData().get(position-1).setIsChoose(1);
                search_id.remove(id);
                search_id.put(id, yw_map.get(id).getData().get(position-1).getId()+"");
                String info =  search_id.toString();
                requestGWData(info);
            }
        });
        final View headView = LayoutInflater.from(this).inflate(R.layout.view_popuwindow_base_tjzl_item, null);


        adapter.addHeaderView(headView);
        headView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.dismiss();
                hideAllStatu();
                for (int i = 0; i < yw_map.get(id).getData().size(); i++) {
                    yw_map.get(id).getData().get(i).setIsChoose(0);
                    yw_map.get(id).getData().get(i).setHeadIsChoose(1);
                }

                search_id.remove(id);
                search_id.put(id,0+"");
                requestGWData(search_id.toString());

            }
        });
    }


    /**
     * 初始化popupwindow弹出框
     */
    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public void showPopupwindowSX(int view_layout_id, View rootview, BaseAdapter adapter, BaseAdapter adapter_two) {
        View popwindow_view = LayoutInflater.from(this).inflate(view_layout_id, null);
        int pop = popwindow_view.getHeight();
        //处理popWindow 显示内容
        if (adapter_two != null) {
            handleListViewSX(popwindow_view);
        } else {
            handleListView(popwindow_view, adapter);
        }

        popupWindow = new PopupWindow(popwindow_view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);

        popupWindow.setTouchable(true);

        popupWindow.setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                hideAllStatu();
                return false;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });

         //如果不设置PopupWindow的背景，无论是点击外部区域还是Back键都无法dismiss弹框
         //我觉得这里是API的一个bug
        popupWindow.setBackgroundDrawable(getResources().getDrawable(R.color.white));

        // 设置好参数之后再show
        popupWindow.showAsDropDown(rootview);
        //显示PopupWindow

    }

    /**
     * 处理弹出的popuwindwo 业务
     *
     * @param contentView
     */
    private void handleListViewSX(View contentView) {
        RecyclerView recyclerView = (RecyclerView) contentView.findViewById(R.id.search_yw_sx_one);
        recyclerView_two = (RecyclerView) contentView.findViewById(R.id.search_yw_sx_two);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);
        adapter_four.addFootView(LayoutInflater.from(this).inflate(R.layout.footer_line, null));
        recyclerView.setAdapter(adapter_four);



        adapter_four.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                //handlerFour(mdata.get(position).getId());

                for (int i = 0; i < mdata.size(); i++) {
                    mdata.get(i).setLineshow(0);
                }
                mdata.get(position).setLineshow(1);
                adapter_four.notifyDataSetChanged();
                ci_position = position;
            }
        });

        recyclerView_two.setLayoutManager(new LinearLayoutManager(this));
        recyclerView_two.setAdapter(adapter_four_two);
        callback = new CallBackYW() {
            @Override
            public void doSomething(final int id) {
                mdata_four_two = yw_map.get(id).getData();
                adapter_four_two.mDatas = mdata_four_two;
                adapter_four_two.notifyDataSetChanged();
            }
        };

        adapter_four_two.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                popupWindow.dismiss();

                for (int i = 0; i < yw_map.get(cj_map_id).getData().size(); i++) {
                    yw_map.get(cj_map_id).getData().get(i).setIsChoose(0);
                    yw_map.get(cj_map_id).getData().get(i).setHeadIsChoose(0);
                }

                yw_map.get(cj_map_id).getData().get(position).setIsChoose(1);
                search_id.remove(cj_map_id);
                search_id.put(cj_map_id, yw_map.get(cj_map_id).getData().get(position).getId()+"");
                String info =  search_id.toString();
                requestGWData(info);
            }
        });

    }


    /**
     * 先将所有的设置为没有点中
     */
    private void hideAllStatu() {
        searchYwOne.setStatu(false);
        searchYwTwo.setStatu(false);
        searchYwThree.setStatu(false);
        searchYwFour.setStatu(false);
    }

}
